﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DevExpressDemos.Controls.GridControl
{
    public partial class 显示多选框 : Frm_GridControlDemo
    {
        public 显示多选框()
        {
            InitializeComponent();
            ShowCheckBox();
        }
        private void ShowCheckBox()
        {
            gridView1.OptionsSelection.MultiSelect = true;  //设置为多选
            gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; //显示多选框
            gridView1.OptionsSelection.CheckBoxSelectorColumnWidth = 28;  //设置多选框列的长度
        }

        private void Btn_GetSels_Click(object sender, EventArgs e)
        {
            int[] RowIndexs = gridView1.GetSelectedRows();
            if (RowIndexs.Length == 0)
                XtraMessageBox.Show("没有选中的数据","提示");
            else
            {
                string str = "";
                RowIndexs.ToList().ForEach(p => str += "," + p);
                str = str.Substring(1);
                XtraMessageBox.Show($"你选中了第{str}行！","提示");
            }
        }

        private void Btn_DelSels_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("是否删除选中行？", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                gridView1.DeleteSelectedRows();
            }
        }
    }
}